#include "ccontrolbar.h"
#include "ccalwindow.h"

#include <buola/image/cimage.h>
#include <buola/image/cgc.h>
#include <buola/gui/cicon.h>
#include <buola/image/cfont.h>
#include <buola/gui/cmenu.h>
#include <buola/gui/cconfig.h>
#include <buola/image/cpattern.h>
#include <buola/datetime/cdatetime.h>
#include <buola/widgets/cbutton.h>

#include <buola/widgets/cscrollbar.h>

namespace buola { namespace bcal {

CControlBar::CControlBar()
{
    SetPreferredSize(CSize_d(40,40));

    SetPointer(gui::CPointer::STOCK_DEFAULT);

    mLeftButton=new gui::CButton;
    mLeftButton->SetIconImage(ICON_STOCK_PREVIOUS);
    mLeftButton->ePressed.Connect(sPrevious);

    mRightButton=new gui::CButton;
    mRightButton->SetIconImage(ICON_STOCK_NEXT);
    mRightButton->ePressed.Connect(sNext);

    mTodayButton=new gui::CButton;
    mTodayButton->SetIconImage("go-jump-today");
    mTodayButton->ePressed.Connect(sToday);

    mDayButton=new gui::CButton;
    mDayButton->SetIconImage("view-calendar-day");
    mDayButton->ePressed.Connect(&CControlBar::OnViewChange,this,(int)CCalWindow::VIEW_DAY);

    mWeekButton=new gui::CButton;
    mWeekButton->SetIconImage("view-calendar-week");
    mWeekButton->ePressed.Connect(&CControlBar::OnViewChange,this,(int)CCalWindow::VIEW_WEEK);

    mMonthButton=new gui::CButton;
    mMonthButton->SetIconImage("view-calendar-month");
    mMonthButton->ePressed.Connect(&CControlBar::OnViewChange,this,(int)CCalWindow::VIEW_MONTH);

    using gui::operator"" _perc;
    Add(mLeftButton,50_perc-124,8,50_perc-100,32);
    Add(mRightButton,50_perc+100,8,50_perc+124,32);

    Add(mTodayButton,8,8,32,32);

    Add(mDayButton,100_perc-88,8,100_perc-64,32);
    Add(mWeekButton,100_perc-60,8,100_perc-36,32);
    Add(mMonthButton,100_perc-32,8,100_perc-8,32);

    SetBackColor({1,1,1});
}

CControlBar::~CControlBar()
{
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
////////////////////////// Interface //////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

void CControlBar::SetCaption(const std::wstring &pCaption)
{
    mCaption=pCaption;
    Refresh();
}


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////// Event handlers ////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

void CControlBar::OnExpose(const gui::CExposeEvent &pE)
{
    img::CGC *lGC=pE.mGC;

    lGC->SetStockFont(L"title");
    
    lGC->SetSource(img::CColor(0.2,0.2,0.2));
    lGC->DrawText({Size().x/2,Size().y/2},mCaption,img::ETextPos::CENTER);
}    

void CControlBar::OnButtonDown(const gui::CMouseEvent &pE)
{
}

void CControlBar::OnButtonUp(const gui::CMouseEvent &pE)
{
}

void CControlBar::OnMouseMove(const gui::CMouseEvent &pE)
{
}

void CControlBar::OnSize(const gui::CGeometryEvent &pE)
{
}

void CControlBar::OnViewChange(int pType)
{
    sChangeView(pType);
}

/*namespace buola*/ } /*namespace bcal*/ }
